import requests
import datetime
import xlsxwriter
import time
import pymysql
from DBUtils.PooledDB import PooledDB
import threading
import math
import pandas as pd
from time import *


ID = "ww7b4086d88a144eec"
SECRET = "QqZ9Au1EwEDc1PyvcZaAgJBhaPDeK1z5zinENKHLL1Q"

# 获取access_token
url_get_access_token = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + ID + "&corpsecret=" + SECRET
def get_access_token(ID,SECRET):
    access_token_json = requests.get(url_get_access_token).json()
    print(access_token_json)
    while access_token_json['errcode'] != 0:
        get_access_token(ID, SECRET)
        time.sleep(2)
    access_token = access_token_json['access_token']
    return access_token

# access_token缓存
access_token = get_access_token(ID,SECRET)

url_add_join_group = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/add_join_way?access_token=" + access_token

add_group_infrom = {
	"scene": 2,
	"remark": "aa_remark",
	"auto_create_room": 1,
	"room_base_name" : "销售客服群",
	"room_base_id" : 1,
	"chat_id_list": [
		"wrWRjVEQAAA8XTL9K0tJ_WgtscoxQr1w",
		"wrWRjVEQAAwEcRYvJi9lXhHTGxYqSDrw",
        "wrWRjVEQAADBUre9emu1DtkRYISsKwVw",
        "wrWRjVEQAAszELRumGC-AP3qWWkGk4pA",
        "wrWRjVEQAACoREcNcfzR8iJMqKUdf-cw",
        "wrWRjVEQAAVfI0-voqmZRUSYTMMchxzw",
        "wrWRjVEQAAne6jLFacRNpT5VKJdSudoQ",
        "wrWRjVEQAA0NfoRQEISrRIIICLpnDSwg",
        "wrWRjVEQAAV30PSdJ5haZmb3WjoNtLUQ",
        "wrWRjVEQAAjAM2Ic85mBx9yxUIerkhLw"
	],
	"state" : "aaa"
}

add_join_group = requests.post(url_add_join_group, json=add_group_infrom)
print(add_join_group.json())